package logic

import (
	"context"
	"gorm.io/gorm"
	"person/model/mysql"

	"person/personrpc/internal/svc"
	"person/personrpc/personrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *personrpc.UpdateRequest) (*personrpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line
	user := &mysql.User{
		Model:    gorm.Model{ID: uint(in.UserId)},
		Password: in.Password,
	}
	user.Updata(mysql.DB)
	return &personrpc.UpdateResponse{}, nil
}
